/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package telas;

import controle.ControladorCadastro;
import enumerations.Especie;
import enumerations.Porte;
import exceptions.CadastroException;
import javax.swing.JOptionPane;
import modelo.Acomodacao;

/**
 *
 * @author eduardo
 */
public class TelaCadastroAcomodacao extends javax.swing.JFrame {

    /**
     * Creates new form TelaCadastroAcomodacao
     */
    public TelaCadastroAcomodacao() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jTextFieldAcomodacaoNumero = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jComboBoxAcomodacaoAla = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        jComboBoxAcomodacaoDimensao = new javax.swing.JComboBox();
        jButton1 = new javax.swing.JButton();
        jButtonConsultar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Cadastro de acomodação");

        jLabel1.setText("Código:");

        jTextFieldAcomodacaoNumero.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldAcomodacaoNumeroActionPerformed(evt);
            }
        });
        jTextFieldAcomodacaoNumero.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTextFieldAcomodacaoNumeroKeyPressed(evt);
            }
        });

        jLabel2.setText("Dimensão:");

        jComboBoxAcomodacaoAla.setModel(new javax.swing.DefaultComboBoxModel(Especie.values()));
        jComboBoxAcomodacaoAla.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxAcomodacaoAlaActionPerformed(evt);
            }
        });

        jLabel3.setText("Ala:");

        jComboBoxAcomodacaoDimensao.setModel(new javax.swing.DefaultComboBoxModel(Porte.values()));
        jComboBoxAcomodacaoDimensao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBoxAcomodacaoDimensaoActionPerformed(evt);
            }
        });

        jButton1.setText("Salvar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButtonConsultar.setText("Consultar");
        jButtonConsultar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonConsultarActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(85, 85, 85)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(layout.createSequentialGroup()
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                    .add(jLabel3)
                                    .add(jLabel1)
                                    .add(jLabel2))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(jTextFieldAcomodacaoNumero, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 60, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(jComboBoxAcomodacaoAla, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(jComboBoxAcomodacaoDimensao, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                            .add(jButton1)))
                    .add(layout.createSequentialGroup()
                        .addContainerGap()
                        .add(jButtonConsultar)))
                .addContainerGap(126, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(10, 10, 10)
                .add(jButtonConsultar)
                .add(18, 18, 18)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1)
                    .add(jTextFieldAcomodacaoNumero, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel3)
                    .add(jComboBoxAcomodacaoAla, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel2)
                    .add(jComboBoxAcomodacaoDimensao, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 32, Short.MAX_VALUE)
                .add(jButton1)
                .add(34, 34, 34))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jTextFieldAcomodacaoNumeroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldAcomodacaoNumeroActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldAcomodacaoNumeroActionPerformed

    private void jComboBoxAcomodacaoAlaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxAcomodacaoAlaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jComboBoxAcomodacaoAlaActionPerformed

    private void jTextFieldAcomodacaoNumeroKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldAcomodacaoNumeroKeyPressed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldAcomodacaoNumeroKeyPressed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        try {
            int numero = Integer.valueOf(jTextFieldAcomodacaoNumero.getText());
            Especie ala = Especie.values()[jComboBoxAcomodacaoAla.getSelectedIndex()];
            Porte dimensao = Porte.values()[jComboBoxAcomodacaoDimensao.getSelectedIndex()];
            Acomodacao acomodacao = new Acomodacao(numero, ala, dimensao);

            ControladorCadastro.cadastrar(acomodacao);
            
            JOptionPane.showMessageDialog(this, "Acomodação " + acomodacao + " cadastrada com sucesso.");
        } catch (CadastroException e) {
            JOptionPane.showMessageDialog(this, e.getMessage());
        } catch (NumberFormatException e) {
            JOptionPane.showMessageDialog(this, "Preencha os campos com os tipos de dados adequados.");
        }

    }//GEN-LAST:event_jButton1ActionPerformed

    private void jComboBoxAcomodacaoDimensaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxAcomodacaoDimensaoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jComboBoxAcomodacaoDimensaoActionPerformed

    private void jButtonConsultarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonConsultarActionPerformed
        // TODO add your handling code here:
        TelaConsultaAcomodacao telaConsultaAcomodacao = new TelaConsultaAcomodacao();
        telaConsultaAcomodacao.setLocationRelativeTo(null);
        telaConsultaAcomodacao.setVisible(true);
    }//GEN-LAST:event_jButtonConsultarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(TelaCadastroAcomodacao.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(TelaCadastroAcomodacao.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(TelaCadastroAcomodacao.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(TelaCadastroAcomodacao.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new TelaCadastroAcomodacao().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButtonConsultar;
    private javax.swing.JComboBox jComboBoxAcomodacaoAla;
    private javax.swing.JComboBox jComboBoxAcomodacaoDimensao;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JTextField jTextFieldAcomodacaoNumero;
    // End of variables declaration//GEN-END:variables
}
